import {
  getPage,
} from '../../utils/config';
import wxApi from '../../utils/wxApi';
import api from '../../utils/api';
import {
  http,
} from '../../utils/utils';
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    logged: 0,
    sfData: [{
        "key": "pingceng",
        "name": "平层",
        "price": ""
      },
      {
        "key": "fushi",
        "name": "复式",
        "price": ""
      },
      {
        "key": "bieshu",
        "name": "别墅",
        "price": ""
      },
      {
        "key": "zijianfang",
        "name": "自建房",
        "price": ""
      }
    ],
    sfData2: [{
        "key": 'banbao',
        "name": "半包",
        "price": ""
      },
      {
        "key": 'quanbao',
        "name": "全包",
        "price": ""
      },
      {
        "key": 'quanan',
        "name": "全案",
        "price": ""
      }
    ],
    steps: [{
        title: '需求沟通',
        status: 'completed',
        activeIcon: '/static/img/goutong.png',
      },
      {
        title: '1v1需求沟通',
      },
      {
        title: '需求调查表',
        desc: '提供调查问卷，清晰全面了解业主需求',
      },
      {
        title: '现场量房',
        status: 'completed',
        activeIcon: '/static/img/xianchang.png',
      },
      {
        title: '交房验房',
        desc: '若是第一次交房期，可提供基础验房，帮助交房开展',
      },
      {
        title: '初稿设计（一般需要7-15个工作日）',
        status: 'completed',
        activeIcon: '/static/img/qianyue.png',
      },
      {
        title: '平面方案',
        desc: '平面方案包括:平面规划图',
      },
      {
        title: '设计交底',
        status: 'completed',
        activeIcon: '/static/img/qianyue.png',
      },
      {
        title: '本地项目设计交底',
        desc: '水电交底，木工交底，土建交底，油漆交底，设备交底（如暖通空调），主要主材安装交底，商家图纸审阅',
      },
      {
        title: '异地设计项目',
        desc: '工地到场服务10次',
      },
      {
        title: '硬装施工',
        status: 'completed',
        activeIcon: '/static/img/shigong.png',
      },
      {
        title: '本地项目现场验收或巡检（巡检7次）',
        desc: '设计师或设计助理或项目经理到工地现场巡检或节点验收',
      },
      {
        title: '水电完工照',
      },
    ],
  },

  gochat() {
    var {
      logged,
      shopInfo
    } = this.data;
    console.log(logged);
    if (logged) {
      wxApi.navigateTo(getPage.chat, {
        id: shopInfo.ShopId,
        user_name: shopInfo.ShopName,
        img: shopInfo.picurl,
        touserid: shopInfo.UserId
      });

    } else {
      this.jumpLogin();
    }
  },

  /**
   * 跳转登录页
   */
  jumpLogin() {
    wxApi.setStartPage({
      id: this.data.shopid
    });
    wxApi.navigateTo(getPage.login);
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let shopInfo = JSON.parse(decodeURIComponent(options.shopInfo))
    console.log('shopInfo11111111=======', shopInfo)
    let ld_options = JSON.parse(shopInfo.liangdian)
    let sfData = this.data.sfData;
    let sfData2 = this.data.sfData2;
    let huxingList = {
      pingceng: shopInfo.pingceng,
      bieshu: shopInfo.bieshu,
      zijianfang: shopInfo.zijianfang,
      fushi: shopInfo.fushi,
    }
    let typeList = {
      banbao: shopInfo.banbao,
      quanbao: shopInfo.quanbao,
      quanan: shopInfo.quanan,
    }
    for (let key in huxingList) {
      if (huxingList[key]) {
        sfData.forEach(s_item => {
          if (key == s_item.key) {
            s_item.price = huxingList[key]
          }
        })
      }
    };
    for (let key in typeList) {
      if (typeList[key]) {
        console.log(key)
        sfData2.forEach(s_item => {
          if (key == s_item.key) {
            s_item.price = typeList[key]
          }
        })
      }
    };
    sfData = sfData.filter(f => f.price)
    sfData2 = sfData2.filter(f => f.price)
    // sfData
    /**
     * 获取用户信息 
     */
    let logged, userId = '';
    app.getLogin().then((res) => {
      console.log('getLogin======', res);
      logged = res.code;
      userId = res.data.user.user_id;
    }).catch((res) => {
      logged = res;
    }).finally(() => {
      http.post(api.default, {
        data: {
          action: 'getshopinfo',
          shopid: options.id,
          userid: userId
        }
      }, false).then(res => {
        const {
          data
        } = res.data;
        this.setData({
          shopInfo: data.shop,
        });
      })
      this.setData({
        logged,
        userId,
        shopInfo,
        ld_options,
        sfData,
        sfData2
      });
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})